# !usr/bin/env python
# -*-coding:utf-8 -*-

# @FileName: new_task.py
# @Author:tian
# @Time:06/21/2021

import pika
import sys
import time

connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()

channel.queue_declare(queue='task_queue', durable=True)

message = ' '.join(sys.argv[1:]) or "Hello World! - {}"
for i in range(50):
    channel.basic_publish(
        exchange='',
        routing_key='task_queue',
        body=message.format(i),
        properties=pika.BasicProperties(
            delivery_mode=2,  # make message persistent
        ))
    print(f'[{i}] Send {message}')
    time.sleep(0.2)
connection.close()